import { Injectable, Inject } from '@nestjs/common';
import { Model } from "mongoose"

import { DBCONSTANTS } from '@/database/db.constants';

import { Interface } from './interface/interface.interface';
import { Demand } from '@/demand/interface/demand.interface';
import { SearchInterface } from './interface/search-interface.interface';

@Injectable()
export class InterfaceService {
  // TODO: set model for you. And after delete doc line
  @Inject(DBCONSTANTS.interfaceModel)
  private readonly interfaceModel: Model<Interface>

  /**
   * 新增接口
   * @param interfaceData 接口入参
   */
  async addDemandInterface(interfaceData: Interface): Promise<Interface> {
    const data = this.interfaceModel(interfaceData);
    return await data.save();
  }

  /**
   * 查询需求下对应的接口列表
   * @param userId 用户id
   * @param demandId 需求id
   */
  async searchDemandInterfaceList(searchObj: SearchInterface): Promise<Demand[]> {
    return await this.interfaceModel.find(searchObj);
  }
}
